//
//  CommentListCell.m
//  Doctor
//
//  Created by 阳光 on 16/9/21.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "CommentListCell.h"

@interface CommentListCell ()

@property(nonatomic,strong)UIView *topLine;

@property(nonatomic,strong)UIImageView *userURL;

@property(nonatomic,strong)UILabel *userLabel;

@property(nonatomic,strong)UILabel *user_TimeLabel;

@property(nonatomic,strong)UIImageView *praiseURL;

@property(nonatomic,strong)UILabel *userName_PraiseLabel;

@property(nonatomic,strong)UILabel *userName_CommentLabel;

@end

@implementation CommentListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;
        
        self.userURL.hidden=NO;
        
        self.userLabel.font=Font_Number(13);
        
        self.user_TimeLabel.font=Font_Number(11);
        
        self.praiseURL.hidden=NO;
        
        self.userName_PraiseLabel.font=Font_Number(11);
        
        self.userName_CommentLabel.font=Font_Number(13);
        
        self.backgroundColor=WhiteColor;
        
    }
    return self;
}

// topLine
-(UIView *)topLine
{
    if (!_topLine) {
        _topLine = [UIView new];
        [self.contentView addSubview:_topLine];
        _topLine.backgroundColor=MAIN_BACK_COLOR;
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.left.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(APPW,1));
        }];
    }
    return _topLine;
}

// userURL
-(UIImageView *)userURL
{
    if (!_userURL) {
        _userURL=[[UIImageView alloc]init];
        [self.contentView addSubview:_userURL];
        _userURL.image=[UIImage imageNamed:@"UserHeaderPlace"];
        // 圆角和边框
        ViewBorderRadius(_userURL,kmargin*2,kmargin/kmargin,ClearColor);
        [_userURL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin);
            make.top.mas_equalTo(self.topLine.mas_bottom).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(kmargin*4,kmargin*4));
        }];
    }
    return _userURL;
}

// userLabel
-(UILabel *)userLabel
{
    if (!_userLabel){
        _userLabel=[self getLabelWithText:@"小熊小悟" font:Font_Number(11) textColor:Color909090 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_userLabel];
        [_userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.topLine.mas_bottom).offset(kmargin);
            make.left.mas_equalTo(self.userURL.mas_right).offset(kmargin);
        }];
    }
    return _userLabel;
}

// user_TimeLabel
- (UILabel *)user_TimeLabel
{
    if (!_user_TimeLabel) {
        _user_TimeLabel=[self getLabelWithText:@"2016-07-29 13:34" font:Font_Number(11) textColor:Color909090 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_user_TimeLabel];
        [_user_TimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.userURL.mas_right).offset(kmargin);
            make.top.mas_equalTo(self.userLabel.mas_bottom).offset(kmargin/5);
        }];
    }
    return _user_TimeLabel;
}


// praiseURL
-(UIImageView *)praiseURL
{
    if (!_praiseURL) {
        _praiseURL=[[UIImageView alloc]init];
        [self.contentView addSubview:_praiseURL];
        _praiseURL.image=[UIImage imageNamed:@"praise"];
        
        [_praiseURL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.userName_PraiseLabel.mas_left).offset(-kmargin/2);
            make.centerY.mas_equalTo(self.userURL.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(kmargin,kmargin));
        }];
    }
    return _praiseURL;
}

// userName_PraiseLabel
- (UILabel *)userName_PraiseLabel
{
    if (!_userName_PraiseLabel) {
        _userName_PraiseLabel=[self getLabelWithText:@"2016" font:Font_Number(11) textColor:Color909090 textAlignment:NSTextAlignmentRight lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_userName_PraiseLabel];
        [_userName_PraiseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.praiseURL.mas_right).offset(kmargin/2);
            make.centerY.mas_equalTo(self.userURL.mas_centerY);
            make.right.mas_equalTo(-kmargin*3/2);
        }];
    }
    return _userName_PraiseLabel;
}


// userName_CommentLabel
-(UILabel *)userName_CommentLabel
{
    if (!_userName_CommentLabel) {
        _userName_CommentLabel=[self getLabelWithText:@"上海祈贝健康管理咨询有限公司是国内一家利用移动医疗和人工智能管理技术，为不孕不育患者和家庭" font:Font_Number(13) textColor:Color333333 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_userName_CommentLabel];
        [_userName_CommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.userURL.mas_bottom);
            make.left.mas_equalTo(self.userURL.mas_right).offset(kmargin);
            make.right.mas_equalTo(-kmargin);
        }];
    }
    return _userName_CommentLabel;
}


-(void)setCommentListModel:(CommentListModel *)commentListModel
{
    _commentListModel=commentListModel;
    
    [_userURL sd_setImageWithURL:[NSURL URLWithString:commentListModel.user_image] placeholderImage:[UIImage imageNamed:@"UserHeaderPlace"]];
    _userLabel.text=commentListModel.name;
    
    _userName_PraiseLabel.text=commentListModel.zan_count;
    
    _userName_CommentLabel.text=commentListModel.content;
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    // 设置时区
    NSTimeZone *timeZone=[NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    // 时间戳转时间的方法
    NSDate *timesp=[NSDate dateWithTimeIntervalSince1970:[commentListModel.create_time integerValue]];
    NSString *timesStr=[formatter stringFromDate:timesp];
    _user_TimeLabel.text=timesStr;
}

@end
